﻿using FDStudio.Core.Entities;
using FDStudio.Core.Entities.Query;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;

namespace FDStudio.Core.Repositories
{
    /*
     CreatedOn: 2018-01-25
     CreatedBy: Jackie Lee(天宇遊龍)
     */
    /// <summary>
    /// 只读仓储
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IReadOnlyRepository<T> : IRepository<T> where T : class, IEntity
    {
        T Get(long id);

        T Get(Expression<Func<T, bool>> condition);

        IEnumerable<T> GetList(Expression<Func<T, bool>> condition);

        /// <summary>
        /// 含排序
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        IEnumerable<T> GetList(Expression<Func<T, bool>> condition, IQueryOrder<T> orderBy);

        /// <summary>
        /// 获取条数
        /// </summary>
        /// <param name="condition">条件</param>
        /// <returns></returns>
        int Count(Expression<Func<T, bool>> condition);

        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="condition">条件</param>
        /// <returns></returns>
        bool Exists(Expression<Func<T, bool>> condition);

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameter">可为IDbDataParameter、IDbDataParameter[]、对象</param>
        /// <param name="read">读取操作</param>
        /// <returns></returns>
        void ExecuteDataReader(string sql, object parameter, Action<IDataReader> read, CommandType commandType = CommandType.Text);

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameter">可为IDbDataParameter、IDbDataParameter[]、对象</param>
        /// <returns></returns>
        U ExecuteScalar<U>(string sql, object parameter);
    }
}
